﻿<%@ WebHandler Language="C#" Class="weekplancell" %>

using System;
using System.Web;
using TSqlServer;

public class weekplancell : IHttpHandler
{
    public void ProcessRequest (HttpContext context) {
        string inman = context.Request["myuid"].ToString();
        string plandate=context.Request["plandate"].ToString();
        string plantime = context.Request["plantime"].ToString();
        string plantimenum = context.Request["plantimenum"].ToString();
        string plancontent = context.Request["plancontent"].ToString();
        string planmans = context.Request["planmans"].ToString();

        TWeekPlan oPlan = new TWeekPlan();
        oPlan.Plandate = System.Convert.ToDateTime(plandate);
        oPlan.Plantime = plantime;
        oPlan.PlantimeNum = System.Convert.ToInt32(plantimenum);
        oPlan.PlanContent = plancontent;
        oPlan.PlanMans = planmans;
        oPlan.Status = 0;
        oPlan.InMan = inman;
        oPlan.Insert();

        char[] parschar ={ ',' };
        string[] mans = planmans.Split(parschar);
        for (int i = 0; i < mans.Length; i++)
        {
            string manname = mans[i];
            string sSql = "select uid from t_user where bigname='" + manname + "'";
            TSqlDBReader oReader = new TSqlDBReader(sSql);
            if (oReader.FDataReader.Read())
            {
                oPlan.InMan = oReader.FDataReader.GetValue(0).ToString();
                oPlan.Insert();
            }
            oReader.Free();
        }

        context.Response.ContentType = "text/plain";
        context.Response.Write(TDateTime.GetPlans(inman, Convert.ToDateTime(plandate), plantime, Convert.ToInt32(plantimenum)));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

    private string GetPlans(string inman, DateTime plandate, string plantime, int plantimenum)
    {
        string result = "";

        string sSql = "select plancontent,planmans from t_plan where inman='" + inman + "' and plandate='" + plandate.ToString("yyyy-MM-dd") + "' and plantime='" + plantime + "' and plantimenum=" + plantimenum.ToString() + " order by iid desc";
        TSqlDBReader oReader = new TSqlDBReader(sSql);
        while (oReader.FDataReader.Read())
        {
            result += "<div>·";
            result += oReader.FDataReader.GetValue(0).ToString();
            if (oReader.FDataReader.GetValue(1).ToString() != "")
            {
                result += "(" + oReader.FDataReader.GetValue(1).ToString() + ")";
            }
            result += "</div>";
        }
        oReader.Free();

        if (result == "")
        {
            result = "&nbsp;";
        }

        return result;
    }
}